//
//  UIImage+extension.swift
//  测试-图片选择器
//
//  Created by shmily on 15/8/9.
//  Copyright © 2015年 shmilyAshen. All rights reserved.
//

import UIKit

extension UIImage {
    
    /// 按照比例缩放图像
    /// :param: maxWidth 图像的最大宽度
    func scaleImage(maxWidth: CGFloat) ->UIImage{
        if size.width < maxWidth {
            return self
        }
        let retio = size.height / size.width
        let s = CGSize(width: maxWidth, height: maxWidth * retio)
        
        //开启图形上下文
        UIGraphicsBeginImageContext(s)
        drawInRect(CGRect(origin: CGPointZero, size: s))
        
        let img = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        return img
    }
    
}
